package client.request;


import client.Client;
import unit.data.Message;
import unit.data.TextMessage;
import unit.request.*;

import java.io.IOException;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: victorn
 * Date: 8/22/11
 * Time: 11:33 PM
 * To change this template use File | Settings | File Templates.
 */
public class RequestWorker {

    Client client;

    public RequestWorker(Client client) {
        this.client = client;
    }

    public void createNewUser(String login, String password) {
        try {
            client.connector.send(new CreateNewUserRequest(0, login, password));
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }


    public void login(String login, String password) {
        try {
            client.connector.send(new LoginRequest(0, login, password));
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

    public void sendMessage(String text, int receiverId) {
        Message msg = new TextMessage(text, client.clientID, receiverId);

        msg.setTime(new Date().getTime());

        try {
            client.connector.send(new SendMessageRequest(0, client.currentSession, msg));
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

    }

    public void addBuddyToContacts(int buddyId) {
        try {
            client.connector.send(new AddContactRequest(0, client.currentSession, client.clientID, buddyId));
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

    }

    public void requestContactsList(String[] projective) {
        try {
            client.connector.send(new GetContactListRequest(0, client.clientID, client.currentSession, projective));
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

    public void searchUser(String username) {
        try {
            client.connector.send(new SearchUserRequest(0, client.clientID, client.currentSession, username));
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
}
